﻿using System.ComponentModel;
using Loki.Utils;
using Luna.Connectors;
using Luna.Connectors.ZohoCRM;

namespace Luna.UI.Configuration
{
    public class ZohoCRMConnectorViewModel : ConnectorViewModel
    {
        public override ConnectorType Type
        {
            get { return ConnectorType.ZohoCRM; }
        }

        #region ApiKey

        private static PropertyChangedEventArgs _ApiKeyChangedArgs = ObservableHelper.CreateChangedArgs<ZohoCRMConnectorViewModel>(x => x.ApiKey);

        private static PropertyChangingEventArgs _ApiKeyChangingArgs = ObservableHelper.CreateChangingArgs<ZohoCRMConnectorViewModel>(x => x.ApiKey);

        private string _ApiKey;

        public string ApiKey
        {
            get
            {
                return _ApiKey;
            }

            set
            {
                if (value != _ApiKey)
                {
                    NotifyChanging(_ApiKeyChangingArgs);
                    _ApiKey = value;
                    NotifyChangedAndDirty(_ApiKeyChangedArgs);
                }
            }
        }

        #endregion ApiKey

        protected override void LoadValues(IConnectorConfiguration P_Configuration)
        {
            base.LoadValues(P_Configuration);

            IZohoCRMSettings L_Settings = P_Configuration as IZohoCRMSettings;
            if (L_Settings != null)
            {
                ApiKey = L_Settings.APIKey;
            }
        }

        protected override void ReadValues(IConnectorConfiguration P_Configuration)
        {
            base.ReadValues(P_Configuration);

            IZohoCRMSettings L_Settings = P_Configuration as IZohoCRMSettings;
            if (L_Settings != null)
            {
                L_Settings.APIKey = ApiKey;
            }
        }
    }
}